package com.zigong.app.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.zigong.app.R;
import com.zigong.app.base.BaseActivity;
import com.zigong.app.beans.LiveItem;
import com.zigong.app.ui.activities.LivingActivity;
import com.zigong.app.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuxipan on 2017-11-14.
 */

public class SearchMoreResultLiveHolder extends BaseSearchReultHolder<LiveItem> implements View.OnClickListener {

    @BindView(R.id.item_live_item_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_live_list_mode)
    protected CustomFontTextView mode;
    @BindView(R.id.item_live_item_title)
    protected CustomFontTextView title;

    @BindView(R.id.item_live_label_date)
    protected CustomFontTextView date;
    @BindView(R.id.item_live_label_channel)
    protected CustomFontTextView channel;

    private LiveItem liveItem;

    public SearchMoreResultLiveHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(LiveItem liveItem) {
        this.liveItem = liveItem;
        if (liveItem.isLiving()) {
            mode.setBackgroundResource(R.drawable.living_bg);
            mode.setText(R.string.livinging);
        } else {
            mode.setBackgroundResource(R.drawable.live_review_bg);
            mode.setText(R.string.retrospect);
        }
        mode.setVisibility(View.GONE);
        title.setText(liveItem.getTitle());
        date.setText(DateUtils.formatDate(DateUtils.getDataDate(liveItem), ""));
        channel.setText(liveItem.getChannelName());
        if (!TextUtils.isEmpty(liveItem.getLiveImg())) {
            GlideUtil.loadImgLarge169Def(context, liveItem.getLiveImg(), img);
        }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, LivingActivity.class);
        intent.putExtra(BaseActivity.EX_URL, liveItem.getLiveContentUrl());
        intent.putExtra(BaseActivity.EX_DATA, liveItem.getLiveImg());
        context.startActivity(intent);
    }
}
